<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_animatorLine"></title>
    <script type="text/javascript" src="./data/animationLineData.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_animatorLine"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_play" onclick="startAnimator()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pause" onclick="pauseAnimator()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>

    var map, layer, animatorVector;
    var style1 = {
        strokeColor: "#b6fb7e",
        strokeWidth: 2
    };
    var style2 =
        {
            strokeColor: "#ffff00",
            strokeWidth: 2
        };
    var style3 =
        {
            strokeColor: "#efad3b",
            strokeWidth: 2
        };
    var style4 =
        {
            strokeColor: "#ef8425",
            strokeWidth: 2
        };
    var style5 =
        {
            strokeColor: "#ef255e",
            strokeWidth: 2
        };
    var style6 =
        {
            strokeColor: "#f80f1a",
            strokeWidth: 2
        };
    var style7 =
        {
            strokeColor: "#ff000",
            strokeWidth: 2
        };

    init();

    function init() {
        if (!document.createElement('canvas').getContext) {
            widgets.alert.showAlert(resources.msg_supportCanvas, false);
            return;
        }
        //初始化地图
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })],
            projection: "EPSG:3857"
        });
        layer = new SuperMap.Layer.CloudLayer();
        //初始化动画矢量图层
        animatorVector = new SuperMap.Layer.AnimatorVector("Train", {}, {
            //设置速度为每帧播放0.01小时的数据
            speed: 0.01,
            //开始时间为12点
            startTime: 12,
            //每秒播放12帧
            frameRate: 12,
            //结束时间设置为15点
            endTime: 15
        });
        map.addLayers([layer, animatorVector]);
        map.setCenter(new SuperMap.LonLat(11586634.286396, 3588716.5813769), 12);
        //增加数据
        addLine();
    }

    //添加线数据
    function addLine() {
        var lineFeatures = [];
        for (var i = 0, len = lines.length; i < len; i++) {
            var arr = [];
            for (var j = 0; j < lines[i][3].length; j++) {
                var point = new SuperMap.Geometry.Point(lines[i][3][j][0], lines[i][3][j][1]);
                arr.push(point);
            }
            var line = new SuperMap.Geometry.LineString(arr);
            var style;
            if (lines[i][2] == 30) {
                style = style1;
            }
            else if (lines[i][2] == 31) {
                style = style2;
            }
            else if (lines[i][2] == 32) {
                style = style3;
            }
            else if (lines[i][2] == 33) {
                style = style4;
            }
            else if (lines[i][2] == 34) {
                style = style5;
            }
            else if (lines[i][2] == 35) {
                style = style6;
            }
            else if (lines[i][2] == 36) {
                style = style7;
            }
            var lineFeature = new SuperMap.Feature.Vector(line, {
                FEATUREID: lines[i][0],
                TIME: lines[i][1],
                TEMPERATURE: lines[i][2]
            }, style);


            lineFeatures.push(lineFeature);
        }
        animatorVector.addFeatures(lineFeatures);
    }

    //开始播放动画
    function startAnimator() {
        animatorVector.animator.start();
    }

    //暂停播放动画
    function pauseAnimator() {
        animatorVector.animator.pause();
    }

</script>

</body>
</html>